<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Register</title>
    <meta charset="UTF-8">
    <script type="text/javascript">
        function validatePassword() {
            const password = document.getElementById("password").value;
            const confirmPassword = document.getElementById("confirmPassword").value;

            if (password !== confirmPassword) {
                alert("两次输入的密码不一致，请重新输入！");
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
<div style="margin: 20px;">
    <h3>用户注册</h3>

    <form th:action="@{/register}" method="post" onsubmit="return validatePassword()">
        <div>
            <label>用户名:</label>
            <input type="text" name="username" required/>
        </div>
        <div>
            <label>密&nbsp;&nbsp;码:</label>
            <input type="password" id="password" name="password" required/>
        </div>
        <div>
            <label>确认密码:</label>
            <input type="password" id="confirmPassword" required/>
        </div>
        <div style="margin-top: 10px;">
            <button type="submit">注册</button>
        </div>
        <div th:if="${param.error}" style="color: red; margin-top: 10px;">
            用户名已存在或注册失败
        </div>
    </form>
</div>
</body>
</html>